#include"sqlconnect.h"
void sqlconnect(QSqlDatabase db){
    if(db.isOpen())
    {
        qDebug()<<"open now";
    }
    else
    {
        //db=QSqlDatabase::addDatabase("QMYSQL");

        //QSqlDatabase db;
        if(QSqlDatabase::contains("qt_sql_default_connection"))
          db = QSqlDatabase::database("qt_sql_default_connection");
        else
          db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setUserName("root");
        db.setPassword("123456");
        db.setDatabaseName("ZZB");
        bool ok=db.open();
        if(ok)
        {
        qDebug()<<"已连接数据库";
        }
        else
        {
            qDebug()<<"连接失败"<<db.lastError();
        }
    }
}
